﻿@model TDT.Land.Entity.Pro_Land
@{
    ViewBag.Title = "Land_List";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@section HeaderContent{
    <script src="../../Scripts/editor/ckeditor.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {
            $("#fuser").ajaxForm({
                iframe: true,
                dataType: "json",
                beforeSubmit: function () {
                    // su kien truoc khi up image
                },
                success: function (result) {
                    cusAlert("Lưu thành công!");
                    setTimeout(function () {
                        onCancel();
                    }, 500);                    
                },
                error: function (xhr, textStatus, errorThrown) {
                    cusAlert("Có lỗi xảy ra trong quá trình lưu dữ liệu... Vui lòng liên hệ quản trị viên");
                }
            });
        });


        $(document).ready(function () {    
            CKEDITOR.replace('Description');            
            $("#ProvinceId").change(function () {
                var proId = this.value;
                var dt = new Date();
                var href = "/Home/getDistrict?ProId=" + proId + "&dt=" + dt.getTime();
                $("#div_district").load(href);
            });

        });

        function onsave() {

            var arrFied = new Array("LandName", "url", "Code", "LandPrice", "Address", "LandStatus", "Notes");
            if (validateNotNull(arrFied))
                $("#fuser").submit();
        }
        function onCancel() {
            window.location.assign("/ProLand/AD_LandList");
        }

        function SetAltValue(value) {
            var _value = change_alias(value);
            $("#url").val(_value);
        }

        function change_alias(alias) {
            var str = alias;
            str = str.toLowerCase();
            str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ |ặ|ẳ|ẵ/g, "a");
            str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
            str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
            str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ |ợ|ở|ỡ/g, "o");
            str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
            str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
            str = str.replace(/đ/g, "d");
            str = str.replace(/!|@@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g, "-");
            /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */
            str = str.replace(/-+-/g, "-"); //thay thế 2- thành 1-
            str = str.replace(/^\-+|\-+$/g, "");
            //cắt bỏ ký tự - ở đầu và cuối chuỗi
            return str;
        }

    </script>
}
@section Toolbar {
    <a class="btn_boder btn_save" onclick="onsave()">Save</a> 
    <a onclick="onCancel()" class="close btn_boder btn_cancel">Cancel</a> 
    @*<a class="btn_boder btn_back" onclick="onCancel()">Back List</a>*@
}
<div>
    <form id="fuser" action="/ProLand/LandAction" method="post" enctype="multipart/form-data">
    <table class="tbEdit" cellpadding="0" cellspacing="0">
        <tr>
            <th style="width: 150px">
            </th>
            <td style="width: 150px">
            </td>
            <th style="width: 100px">
            </th>
            <td style="width: 150px">
            </td>
        </tr>
        <tr>
            <th>@Pro_Land.FieldName.LandName.Translate() <span class="sp_batBuoc">(*)</span> </th>
            <td colspan="3">@Html.TextBoxFor(m => m.LandName, new { onkeyup = "SetAltValue(this.value);" })</td>
        </tr>
        <tr>
            <th>Url pagram <span class="sp_batBuoc">(*)</span></th>
            <td colspan="3">@Html.TextBox("url")</td>
        </tr>
        <tr>
            <th>@Pro_Land.FieldName.LandCode.Translate() <span class="sp_batBuoc">(*)</span></th>
            <td colspan="3">@Html.TextBoxFor(m => m.Code)</td>
            
        </tr>

        
        <tr>
            <th>@*@Pro_Land.FieldName.LandImg.Translate()*@ Img</th>
            <td colspan="3">
                <div>
                   @{
                       if(Model!= null && !string.IsNullOrEmpty(Model.LandImage)){
                           <img alt="" src="../Uploads/@Model.LandImage" width="150px;" />
                       }
                       }
                </div> 
                <div>
                <input type="file" name="fileName" id="fileName" />
                @Html.HiddenFor(mbox=>mbox.LandImage)
                </div>
            </td>
        </tr>

        <tr>
            <th>@Pro_Land.FieldName.LandPrice.Translate() <span class="sp_batBuoc">(*)</span></th>
            <td>@Html.TextBoxFor(m => m.LandPrice, new { style = "width:135px" })
                &nbsp;
                @Html.DropDownListFor(m => m.Currency, (List<SelectListItem>)ViewBag.select_Currency, new { style = "width:55px" })
            </td>
            <th>@Pro_Land.FieldName.LandAddress.Translate() <span class="sp_batBuoc">(*)</span></th>
            <td>@Html.EditorFor(m => m.Address)</td>
        </tr>
        <tr>
            <th>@Pro_Land.FieldName.LandStatus.Translate() <span class="sp_batBuoc">(*)</span></th>
            <td>
                @Html.DropDownListFor(m => m.LandStatus, (List<SelectListItem>)ViewBag.select_LandStatus, new { style = "width:138px" })
            </td>
            <th>@Pro_Land.FieldName.LandSquare.Translate()</th>
            <td>
                @Html.EditorFor(m => m.LandSquare)
            </td>
        </tr>
        <tr>
            <th>@Pro_Land.FieldName.LandStatusDate.Translate() 
            </th>
            <td>
                @Html.EditorFor(m => m.LandStatusDate)
            </td>
            <th>@Pro_Land.FieldName.LandOrient.Translate()
            </th>
            <td>
                @Html.EditorFor(m => m.LandOrient)
            </td>
        </tr>
        <tr>
            <th>@Pro_Land.FieldName.NumFloor.Translate()
            </th>
            <td>
                @Html.EditorFor(m => m.Floor)
            </td>
            <th>@Pro_Land.FieldName.NumRooms.Translate()
            </th>
            <td>
                @Html.EditorFor(m => m.Rooms)
            </td>
        </tr>
        <tr>
            <th>@Pro_Land.FieldName.LandFurniture.Translate()
            </th>
            <td>
                @Html.EditorFor(m => m.Furniture)
            </td>
            <th>@Pro_Land.FieldName.LandType.Translate()
            </th>
            <td>
                @Html.DropDownListFor(m => m.LandTypeId, (List<SelectListItem>)ViewBag.select_HomeType, new { style = "width:138px" })
            </td>
        </tr>
        <tr>
            <th>@Pro_Land.FieldName.Province.Translate()
            </th>
            <td>
                @Html.DropDownListFor(m => m.ProvinceId, (List<SelectListItem>)ViewBag.select_Province, new { style = "width:138px" })
            </td>
            <th>@Pro_Land.FieldName.District.Translate()
            </th>
            <td>
                <div id="div_district">
                    @Html.Partial("US_District_view")
                </div>
                @*@Html.DropDownListFor(m => m.DistrictId, (List<SelectListItem>)ViewBag.select_District, new { style = "width:138px" })*@
            </td>
           
        </tr>
        <tr>
            <th>@Pro_Land.FieldName.Ward.Translate()
            </th>
            <td>
                <div id="div_Ward">
                    @Html.Partial("US_Ward_view")
                </div>
                @*@Html.DropDownListFor(m => m.WardId, (List<SelectListItem>)ViewBag.select_Ward, new { style = "width:138px" })*@
            </td>
             <th>@Pro_Land.FieldName.LandBDSType.Translate()
            </th>
            <td>
                @Html.DropDownListFor(m => m.LandTypeBDSId, (List<SelectListItem>)ViewBag.select_BDSType, new { style = "width:138px" })
            </td>
        </tr>
        
        <tr>
            <th>@Pro_Land.FieldName.IsShowTop.Translate()
            </th>
            <td colspan="3">
                @Html.EditorFor(m => m.IsShowTop)
            </td>
        </tr>
        
        <tr>
            <th>@*@Pro_Land.FieldName.LandShortDesc.Translate()*@ Mô tả Ngắn <span class="sp_batBuoc">(*)</span></th>
            <td colspan="3">
                @Html.TextAreaFor(mbox=>mbox.Notes)
            </td>
        </tr>


        <tr>
            <th>@Pro_Land.FieldName.LandDescription.Translate() <span class="sp_batBuoc">(*)</span>
            </th>
            <td colspan="3"></td>
        </tr>
        <tr>
            <td colspan="4" style="height:500px;">
               @Html.TextAreaFor(m => m.Description, new { style = "height:500px" })
            </td>
        </tr>

        <tr>
            <td colspan="4" align="center">
                @Html.HiddenFor(m => m.ID)
                @*<input type="button" value="Tạo mới" />*@
            </td>
        </tr>
    </table>
    </form>
</div>

